Skip to content

diff: replace diff crate with in-tree Myers SES engine - #418

Open
shadowmkj wants to merge 3 commits into
uutils:mainfrom
shadowmkj:feat/myers-ses-implementation
Open

shadowmkj wants to merge 3 commits into
uutils:mainfrom
shadowmkj:feat/myers-ses-implementation

Conversation

@shadowmkj

@shadowmkj shadowmkj commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR to evaluate ses (Shortest Edit Script) for sequence comparison using Eugene Myers' diff algorithm, and to compare CodSpeed
performance and hunk compatibility against main and #415 (similar).

ses is the minimal crate implementation of Myers' diff algorithm. https://github.com/shadowmkj/ses

Unlike similar, ses produces hunks that are 1:1 compatible with GNU diff's alignments and tie-breaking .

What changed:

  • Replaced the diff crate dependency with ses across normal_diff, unified_diff, context_diff,
    ed_diff, and side_diff.
  • Added edge-case tests in tests/by-util/test_diff.rs verifying 1:1 GNU diff compatibility
    (symmetrical/asymmetrical ties, replacements, and boundary changes).

@shadowmkj
shadowmkj marked this pull request as ready for review November 19, 2026 14:52
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (b93330b) to head (c626797).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff     @@
##   main   #418   +/-   ##
===========================
===========================

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sylvestre

Copy link
Copy Markdown
Collaborator

sorry but it is unlikely that we will take add this dependency over similar

@shadowmkj

Copy link
Copy Markdown
Contributor Author

That's what I want to know, since similar cannot produce GNU compatible hunks? What is the solution that you are suggesting?

This crate is just temporary and for isolating the core algorithm from this repository (so I can research and play around), and it's small enough to be merged into diffutils itself. That's what I mentioned here: #415 (comment)

@shadowmkj
shadowmkj force-pushed the feat/myers-ses-implementation branch from c626797 to 143b9df Compare November 20, 2026 10:50
@codspeed

codspeed Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by ×31

3 warnings

⚠️ 8 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 3 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 3 benchmarks with a significant change ran in a different software environment

Their base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the changes might come from this difference rather than from the code. Open an affected benchmark to see what changed.

See affected benchmarks

⚡ 3 improved benchmarks
✅ 13 untouched benchmarks
⏩ 16 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ diff_compare_files_different[1000] 10,229.2 ms 18.5 ms ×550
⚡ diff_compare_files_different[100] 103.4 ms 2 ms ×52
⚡ diff_compare_files_equal[25000] 378.2 ms 362.4 ms +4.35%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing shadowmkj:feat/myers-ses-implementation (52afb27) with main (144c91c)

Open in CodSpeed

Footnotes

  1. 16 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@shadowmkj
shadowmkj force-pushed the feat/myers-ses-implementation branch 4 times, most recently from f44ed3d to fd2f7cc Compare November 20, 2026 14:16
@github-actions

Copy link
Copy Markdown

GNU diffutils testsuite comparison:

Test results comparison:
  Current:   TOTAL: 33 / PASSED: 18 / FAILED: 11 / SKIPPED: 4
  Reference: TOTAL: 33 / PASSED: 20 / FAILED: 9 / SKIPPED: 4

Changes from main branch:
  TOTAL: +0
  PASSED: -2
  FAILED: +2

New test failures (2):
  - cmp
  - function-line-vs-leading-space

@shadowmkj
shadowmkj force-pushed the feat/myers-ses-implementation branch from d5915fc to 52afb27 Compare November 27, 2026 21:22
@shadowmkj

Copy link
Copy Markdown
Contributor Author

@sylvestre
I ported the ses crate into the tree itself for this PR. I know it is quite a large change since
it replaces the core diff engine with a clean-room Myers linear-space implementation written from
scratch to guarantee GNU compatibility and performance. I have put a lot of work into validating
both behavior and performance across the diff formats, and I would really appreciate a review when
you get a chance 😃

Landing this will have a huge performance impact and eliminate the O(N*M) memory blowup so OOM
errors on large differing files won't happen anymore:

  • 1 MB differing files (cargo bench): median time drops from 374.8 ms to 1.014 ms (~370x
    faster), and peak heap drops from 628.4 MB to 4.341 MB (~145x less).
  • 10 MB & 25 MB differing files: main OOMs under the O(N*M) allocator, whereas this branch
    completes 10 MB in 13.87 ms (43.07 MB peak heap) and 25 MB in 41.21 ms (90.65 MB peak
    heap).
Metric main (144c91c) feat (52afb27) Improvement
Wall time (real) 1.01s 0.38s 2.66x faster
User CPU time (user) 0.68s 0.29s 2.34x less
System CPU time (sys) 0.12s 0.03s 4.00x less
Instructions retired 11,758,814,744 2,580,127,280 4.56x fewer
Cycles elapsed 2,488,120,172 1,063,937,243 2.34x fewer
Max RSS 371,736,576 B (~354.5 MiB) 8,814,592 B (~8.41 MiB) ~42.2x lower
Peak memory footprint 638,272,352 B (~608.7 MiB) 6,717,824 B (~6.41 MiB) ~95.0x lower
Page reclaims 46,117 701 ~65.8x fewer

(Tested on Macbook Air M2)

@shadowmkj shadowmkj changed the title diff: use ses for Myers sequence comparison diff: replace diff crate with in-tree Myers SES engine Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants